HTMLAudioElement.prototype.stop = function(){
    this.pause();
    this.currentTime = 0.0;
}

String.prototype.Trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function doScroll() {
    if(window.pageYOffset === 0) {
        window.scrollTo(0, 1);
    }
}

window.onorientationchange = function() {
    setTimeout(doScroll,100);
};

window.onresize = function() {
    setTimeout(doScroll,100);
}

var winH=$(window).height();
var utiljs="utils.js";
var notice = LGlobal.platforms == "sohuNews" ? winH < 360 ? "notice_s.png" : "notice.png" : "notice.png";
var loadData = [
    {path:"./js/Plain.js",type:"js"},
    {path:"./js/Player.js",type:"js"},
    {path:"./js/Enemy.js",type:"js"},
    {path:"./js/"+utiljs,type:"js"},
    {path:"./js/Weiba.js",type:"js"},
    {name: "bg", path: "./images/bg.png"},
    {name: "sohu", path: "./images/sohu.png"},
    {name: "pointer", path: "./images/pointer.png"},
    {name: "sharelogo", path: "./images/sharelogo.png"},
    {name: "tips1", path: "./images/tips1_b.png"},
    {name: "tips2", path: "./images/tips2_b.png"},
    {name: "tips3", path: "./images/tips3_b.png"},
    {name: "tips4", path: "./images/tips4_b.png"},
    {name: "tips5", path: "./images/tips5_b.png"},
    {name: "tips6", path: "./images/tips6_b.png"},
    {name: "weiba", path: "./images/weiba.png"},
    {name: "2015", path: "./images/2015.png"},
    {name: "fox", path: "./images/fox.png"},
    {name: "qipao", path: "./images/qipao_b.png"},
    {name: "success", path: "./images/success.png"},
    {name: "fail", path: "./images/fail.png"},
    {name: "newsArea", path: "./images/newsArea.png"},
    {name: "hongbao", path: "./images/hongbao.png"},
    {name: "baozhi", path: "./images/baozhi.png"},
    {name: "notice", path: "./images/"+notice},
    {name: "closeBtn", path: "./images/closeBtn.png"},
    {name: "clickBtn", path: "./images/clickBtn.png"},
    {name: "player", path: "./images/stone.png"},
    {name: "stone2", path: "./images/stone2.png"},
    {name: "remove",path:"./images/remove.png"},
    {name: "dangong", path: "./images/dangong.png"},
    {name: "enemy1",path:"./images/egg1.png"},
    {name: "enemy2",path:"./images/egg2.png"},
    {name: "enemy3",path:"./images/egg3.png"},
    {name: "enemy4",path:"./images/egg4.png"},
    {name:"startBtn",path:"./images/start_button.png"}
];

var eggs_num=0;

var ctrlIndex = 0;

var tipsIndex=1;

var isKit=0;

var tipsListener;

var hitNum=0;

var canShot=true;

var frame = 0,frames = 0;

var datalist = null;

var backLayer,gameLayer,loadingLayer,buttonLayer,plainLayer,bgbitmap,arcLayer,loadingTextLayer,maskLayer,qipaoLayer,qipaoTextLayer;

var player;//狐狸

var shotLayer

var showStone;

var showLoadingGo;

var qipaoTextNew;

var isStart = false;

var p1=getQueryString("p1");

var newsIndex=getRandomNum(0,19);

/*背景音乐*/
var dropSound
var boomSound;
var zhiSound;
var startSound;

function main(){
    if(LGlobal.canTouch){
        LGlobal.stageScale = LStageScaleMode.EXACT_FIT;
        LSystem.screen(LStage.FULL_SCREEN);
    }
    loadingLayer = new LoadingSample2("#fff","#000");
    addChild(loadingLayer);
    LLoadManage.load(
        loadData,
        function(progress){
            loadingLayer.setProgress(progress);
        },
        gameInit
    );
}

/*读取查询字符串*/
function getQueryString(name) {
    var params = location.search.substring(1);
    var paramList = [];
    var param = null;
    var parami;
    if (params.length > 0) {
        if (params.indexOf("&") >= 0) {
            paramList = params.split("&");
        } else {
            paramList[0] = params;
        }
        for (var i = 0, listLength = paramList.length; i < listLength; i++) {
            parami = paramList[i].indexOf(name + "=");
            if (parami >= 0) {
                param = paramList[i].substr(parami + (name + "=").length);
            }
        }
    }
    return param;
}

function gameInit(result){
    datalist = result;
    $("#loadingBg").hide();
    removeChild(loadingLayer);
    initLayer(datalist);
}

/*随机数*/
function getRandomNum(min,max){
    var range = max - min;
    var rand = Math.random();
    return(min + Math.round(rand * range));
}

// 统计数据
var tjObjExtend = {
    u:"lp",
    contentType:"active",
    activeid: 67,
    objType:"h5_active_71_1"
};

window.onload = function() {
    setTimeout(doScroll,100);
    var screenWidth=640;
    var screenHeight;

    if(LGlobal.platforms=="weixin"){
        screenHeight=LGlobal.ios ? 1010 : 890;
    }else{
        screenHeight=LGlobal.ios ? winH<360 ? 800 : 990 : 860;
    }
    init(20,"myCanvas",screenWidth,screenHeight,main,LEvent.INIT);
}

